﻿Public Class frmRackHistory

    Protected dtData As New DataTable
    Protected m_cData As New clsDbCondData

    Private fileName As String = ""
    Private fileSaveTitle As String = ""
    Private serchMaxCount As Integer = 1000

    Dim FromDate As Date
    Dim ToDate As Date
    Dim procFrom As Integer
    Dim procTo As Integer


    Private Sub frmSeach_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'タイトル変更
        Me.Text = "料盒履历检索画面" 'UPD MIAO 2018/8/7

        'コンボボックスの選択肢設定
        createComboBox()

        '最大取得件数設定
        getSerchMaxCount()

        'DataGridViewの設定
        'ヘッダーの自動生成不可
        '設定しないと検索結果を削除した際に、ヘッダーも削除される。
        DataGridView1.AutoGenerateColumns = False

        'ラジオボタンの初期値設定
        rbWaferCase.Checked = True

    End Sub

    '検索ボタン押下処理
    Private Sub btnManufComp_Click(sender As Object, e As EventArgs) Handles btnSerch.Click

        '検索結果欄初期化
        DataGridView1.DataSource = Nothing
        '検索件数初期化
        txtRowCount.Text = 0

        '入力チェック
        If inputCheck() Then
            Exit Sub
        End If

        '検索処理
        serch()

    End Sub

    '入力チェック処理
    Private Function inputCheck()

        'ラックNoが未入力の場合はエラーとする
        If String.IsNullOrEmpty(txtRackNo.Text) Then
            MsgBox(getMsgStr("MSG00015", lblRackNo.Text))
            Return True
        End If

        '日付入力チェック
        Dim FromString As String = DateTimePickerFrom.Text + " " + cmbHourFrom.SelectedValue + ":" + cmbMinuteFrom.SelectedValue + ":00"
        Dim ToString As String = DateTimePickerTo.Text + " " + cmbHourTo.SelectedValue + ":" + cmbMinuteTo.SelectedValue + ":59"
        Try
            FromDate = Date.Parse(FromString)
            ToDate = Date.Parse(ToString)

            If Date.Compare(FromDate, ToDate) = 1 Then
                MsgBox(htMsgMst("MSG10044"))
                Return False
            End If
        Catch ex As Exception
            Return False
        End Try

        '入力値大文字化
        txtRackNo.Text = txtRackNo.Text.ToUpper()

        Return False
    End Function

    '取消ボタン押下処理
    Private Sub Clear_Click(sender As Object, e As EventArgs) Handles btnClear.Click

        '検索条件欄初期化
        txtRackNo.Text = String.Empty
        DateTimePickerFrom.Text = Today.ToString
        cmbHourFrom.SelectedValue = "0"
        cmbMinuteFrom.SelectedValue = "00"
        DateTimePickerTo.Text = Today.ToString
        cmbHourTo.SelectedValue = "23"
        cmbMinuteTo.SelectedValue = "59"
        rbWaferCase.Checked = True

        '検索結果欄初期化
        DataGridView1.DataSource = Nothing
        '検索件数初期化
        txtRowCount.Text = ""

    End Sub

    'コンボボックスの選択肢設定
    Private Sub createComboBox()
        'コンボボックス（時）の設定
        Dim hourTableFrom As New DataTable()
        Dim hourTableTo As New DataTable()
        'DataTableに列を追加
        hourTableFrom.Columns.Add("ID", GetType(String))
        hourTableFrom.Columns.Add("NAME", GetType(String))
        hourTableTo.Columns.Add("ID", GetType(String))
        hourTableTo.Columns.Add("NAME", GetType(String))

        For i As Integer = 0 To 23
            '新しい行を作成
            Dim rowFrom As DataRow = hourTableFrom.NewRow()
            Dim rowTo As DataRow = hourTableTo.NewRow()
            '各列に値をセット
            rowFrom("ID") = i.ToString
            rowFrom("NAME") = i.ToString
            rowTo("ID") = i.ToString
            rowTo("NAME") = i.ToString
            'DataTableに行を追加
            hourTableFrom.Rows.Add(rowFrom)
            hourTableTo.Rows.Add(rowTo)
        Next

        hourTableFrom.AcceptChanges()
        hourTableTo.AcceptChanges()

        'コンボボックスのDataSourceにDataTableを割り当てる
        '月From
        cmbHourFrom.DataSource = hourTableFrom
        cmbHourFrom.DisplayMember = "NAME"
        cmbHourFrom.ValueMember = "ID"
        '月To
        cmbHourTo.DataSource = hourTableTo
        cmbHourTo.DisplayMember = "NAME"
        cmbHourTo.ValueMember = "ID"
        cmbHourTo.SelectedValue = "23"


        'コンボボックス（分）の設定
        Dim minuteTableFrom As New DataTable()
        Dim minuteTableTo As New DataTable()
        'DataTableに列を追加
        minuteTableFrom.Columns.Add("ID", GetType(String))
        minuteTableFrom.Columns.Add("NAME", GetType(String))
        minuteTableTo.Columns.Add("ID", GetType(String))
        minuteTableTo.Columns.Add("NAME", GetType(String))

        For i As Integer = 0 To 59
            '新しい行を作成
            Dim row As DataRow = minuteTableFrom.NewRow()
            Dim rowTo As DataRow = minuteTableTo.NewRow()
            '各列に値をセット
            row("ID") = String.Format("{0:D2}", i)
            row("NAME") = String.Format("{0:D2}", i)
            rowTo("ID") = String.Format("{0:D2}", i)
            rowTo("NAME") = String.Format("{0:D2}", i)
            'DataTableに行を追加
            minuteTableFrom.Rows.Add(row)
            minuteTableTo.Rows.Add(rowTo)
        Next

        minuteTableFrom.AcceptChanges()
        minuteTableTo.AcceptChanges()

        'コンボボックスのDataSourceにDataTableを割り当てる
        '月From
        cmbMinuteFrom.DataSource = minuteTableFrom
        cmbMinuteFrom.DisplayMember = "NAME"
        cmbMinuteFrom.ValueMember = "ID"
        '月To
        cmbMinuteTo.DataSource = minuteTableTo
        cmbMinuteTo.DisplayMember = "NAME"
        cmbMinuteTo.ValueMember = "ID"
        cmbMinuteTo.SelectedValue = "59"

    End Sub


    Private Sub serch()

        '選択したラジオボタンにより変更する。
        If rbWaferCase.Checked Then
            'ウェハケース検索

            '事前に件数取得を行う。
            Dim dtCount As DataTable = getDataCountWaferCase()
            Dim getCountInt As Integer = CInt(DBNULLTOBLANK(dtCount.Rows(0)("COUNT")))

            '検索条件値を超えているかチェックする
            If getCountInt = 0 Then
                '取得件数0件の場合は検索処理を終了する。
                txtRowCount.Text = 0
                MsgBox(htMsgMst("MSG10048"))
                Exit Sub
            ElseIf getCountInt > serchMaxCount Then
                '検索上限値を超えている場合は、メッセージを表示する。
                MsgBox(htMsgMst("MSG10046"))
                '取得件数に最大値を設定する。
                txtRowCount.Text = serchMaxCount
            Else
                '取得件数を設定する。
                txtRowCount.Text = getCountInt
            End If

            'l_lotdataよりデータを取得
            dtData = getDataWaferCase()
            If dtData.Rows.Count > 0 Then
                Me.DataGridView1.DataSource = dtData
            End If

        ElseIf rbRack.Checked Then
            'ラック検索

            '事前に件数取得を行う。
            Dim dtCount As DataTable = getDataCountRack()
            Dim getCountInt As Integer = CInt(dtCount.Rows(0)("COUNT"))

            '検索条件値を超えているかチェックする
            If getCountInt = 0 Then
                '取得件数0件の場合は検索処理を終了する。
                txtRowCount.Text = 0
                MsgBox(htMsgMst("MSG10048"))
                Exit Sub
            ElseIf getCountInt > serchMaxCount Then
                '検索上限値を超えている場合は、メッセージを表示する。
                MsgBox(htMsgMst("MSG10046"))
                '取得件数に最大値を設定する。
                txtRowCount.Text = serchMaxCount
            Else
                '取得件数を設定する。
                txtRowCount.Text = getCountInt
            End If

            'l_lotdataよりデータを取得
            dtData = getDataRack()
            If dtData.Rows.Count > 0 Then
                Me.DataGridView1.DataSource = dtData
            End If

        ElseIf rbMSRack.Checked Then
            'MSラック検索

            '事前に件数取得を行う。
            Dim dtCount As DataTable = getDataCountMsRack()
            Dim getCountInt As Integer = CInt(dtCount.Rows(0)("COUNT"))

            '検索条件値を超えているかチェックする
            If getCountInt = 0 Then
                '取得件数0件の場合は検索処理を終了する。
                txtRowCount.Text = 0
                MsgBox(htMsgMst("MSG10048"))
                Exit Sub
            ElseIf getCountInt > serchMaxCount Then
                '検索上限値を超えている場合は、メッセージを表示する。
                MsgBox(htMsgMst("MSG10046"))
                '取得件数に最大値を設定する。
                txtRowCount.Text = serchMaxCount
            Else
                '取得件数を設定する。
                txtRowCount.Text = getCountInt
            End If

            'l_lotdataよりデータを取得
            dtData = getDataMsRack()
            If dtData.Rows.Count > 0 Then
                Me.DataGridView1.DataSource = dtData
            End If
        End If

    End Sub

    '工程コード一覧取得
    Private Function getProcData() As DataTable
        Dim szSql As String = ""
        szSql &= " SELECT proc_cd "
        szSql &= " FROM PER.t_proc_cd "
        szSql &= " ORDER BY flow_num "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsNothing(dt) Then
            getProcData = New DataTable
        Else
            getProcData = dt
        End If
    End Function

    '検索条件にヒットする件数を取得する。(ウェハケース)
    Private Function getDataCountWaferCase() As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT "
        szSql &= "  COUNT(*) COUNT " 'UPD MIAO 2018/10/31
        szSql &= "FROM "
        szSql &= "    MAT.l_sf_work_rslt_head AS A "
        szSql &= "RIGHT JOIN "
        szSql &= "    ( "
        szSql &= "      SELECT * "
        szSql &= "      FROM "
        szSql &= "      ( "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S311.lot_no as lot_no, "
        szSql &= "            S311.type AS type, "
        szSql &= "            MAX(CASE WHEN S311.seq = '1' THEN S311.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S311.seq = '2' THEN S311.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S311.seq = '3' THEN S311.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S311.seq = '4' THEN S311.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S311.seq = '5' THEN S311.actual_model END) AS rack5 , "
        szSql &= "            S311.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S311 AS S311 "
        szSql &= "        WHERE  "
        szSql &= "             S311.mnf_cnd_tag = 'WAFER CASE NO' "
        szSql &= "             AND  S311.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S31.lot_no AS lot_no, "
        szSql &= "            S31.type AS type, "
        szSql &= "            MAX(CASE WHEN S31.seq = '1' THEN S31.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S31.seq = '2' THEN S31.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S31.seq = '3' THEN S31.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S31.seq = '4' THEN S31.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S31.seq = '5' THEN S31.actual_model END) AS rack5 , "
        szSql &= "            S31.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S31 AS S31 "
        szSql &= "        WHERE  "
        szSql &= "             S31.mnf_cnd_tag = 'WAFER CASE NO' "
        szSql &= "             AND  S31.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A31.lot_no AS lot_no, "
        szSql &= "            A31.type AS type, "
        szSql &= "            MAX(CASE WHEN A31.seq = '1' THEN A31.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A31.seq = '2' THEN A31.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A31.seq = '3' THEN A31.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A31.seq = '4' THEN A31.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A31.seq = '5' THEN A31.actual_model END) AS rack5 , "
        szSql &= "            A31.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A31 AS A31 "
        szSql &= "        WHERE  "
        szSql &= "             A31.mnf_cnd_tag = 'WAFER CASE NO' "
        szSql &= "             AND  A31.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S41.lot_no AS lot_no,  "
        szSql &= "            S41.type AS type, "
        szSql &= "            MAX(CASE WHEN S41.seq = '1' THEN S41.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '2' THEN S41.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '3' THEN S41.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '4' THEN S41.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '5' THEN S41.actual_model END) AS rack5 , "
        szSql &= "            S41.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S41 AS S41 "
        szSql &= "        WHERE  "
        szSql &= "             S41.mnf_cnd_tag = 'WAFER CASE NO' "
        szSql &= "             AND  S41.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "      )  UNION_TABLE " 'UPD MIAO 2018/10/31
        szSql &= "      WHERE "
        szSql &= "         UNION_TABLE.rack1 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack2 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack3 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack4 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack5 = '" + txtRackNo.Text + "' "
        szSql &= "    )  B " 'UPD MIAO 2018/10/31
        szSql &= "ON "
        szSql &= "    A.lot_no =  B.lot_no "
        szSql &= "AND "
        szSql &= "    A.opt_time = B.update_time "
        szSql &= "AND "
        szSql &= "    A.type = B.type "
        szSql &= "WHERE "
        szSql &= "    A.koutei_cd in('S311','S31','A31','S41') "
        szSql &= "    ORDER BY B.lot_no, B.update_time, B.type " 'ADD MIAO 2018/10/31


        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsNothing(dt) Then
            getDataCountWaferCase = New DataTable
        Else
            getDataCountWaferCase = dt
        End If
    End Function

    '検索条件にヒットするデータを取得する。(ウェハケース)
    Private Function getDataWaferCase() As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT  "
        szSql &= "    A.lot_no, "
        szSql &= "    A.diff_lot AS wafer_lotno, "
        szSql &= "    A.koutei_cd, "
        szSql &= "    CASE WHEN A.type = '1' THEN '" + htMsgMst("MSG10040") + "' "
        szSql &= "         WHEN A.type = '2' THEN '" + htMsgMst("MSG10041") + "' "
        szSql &= "         WHEN A.type = '3' THEN '" + htMsgMst("MSG10042") + "' "
        szSql &= "    END AS status,  "
        szSql &= "    A.opt_time, "
        szSql &= "    B.rack1, "
        szSql &= "    B.rack2, "
        szSql &= "    B.rack3, "
        szSql &= "    B.rack4, "
        szSql &= "    B.rack5 "
        szSql &= "FROM "
        szSql &= "    MAT.l_sf_work_rslt_head AS A "
        szSql &= "RIGHT JOIN "
        szSql &= "    ( "
        szSql &= "      SELECT * "
        szSql &= "      FROM "
        szSql &= "      ( "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S311.lot_no as lot_no, "
        szSql &= "            S311.type AS type, "
        szSql &= "            MAX(CASE WHEN S311.seq = '1' THEN S311.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S311.seq = '2' THEN S311.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S311.seq = '3' THEN S311.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S311.seq = '4' THEN S311.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S311.seq = '5' THEN S311.actual_model END) AS rack5 , "
        szSql &= "            S311.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S311 AS S311 "
        szSql &= "        WHERE  "
        szSql &= "             S311.mnf_cnd_tag = 'WAFER CASE NO' "
        szSql &= "             AND  S311.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S31.lot_no AS lot_no, "
        szSql &= "            S31.type AS type, "
        szSql &= "            MAX(CASE WHEN S31.seq = '1' THEN S31.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S31.seq = '2' THEN S31.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S31.seq = '3' THEN S31.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S31.seq = '4' THEN S31.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S31.seq = '5' THEN S31.actual_model END) AS rack5 , "
        szSql &= "            S31.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S31 AS S31 "
        szSql &= "        WHERE  "
        szSql &= "             S31.mnf_cnd_tag = 'WAFER CASE NO' "
        szSql &= "             AND  S31.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A31.lot_no AS lot_no, "
        szSql &= "            A31.type AS type, "
        szSql &= "            MAX(CASE WHEN A31.seq = '1' THEN A31.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A31.seq = '2' THEN A31.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A31.seq = '3' THEN A31.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A31.seq = '4' THEN A31.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A31.seq = '5' THEN A31.actual_model END) AS rack5 , "
        szSql &= "            A31.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A31 AS A31 "
        szSql &= "        WHERE  "
        szSql &= "             A31.mnf_cnd_tag = 'WAFER CASE NO' "
        szSql &= "             AND  A31.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S41.lot_no AS lot_no,  "
        szSql &= "            S41.type AS type, "
        szSql &= "            MAX(CASE WHEN S41.seq = '1' THEN S41.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '2' THEN S41.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '3' THEN S41.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '4' THEN S41.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '5' THEN S41.actual_model END) AS rack5 , "
        szSql &= "            S41.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S41 AS S41 "
        szSql &= "        WHERE  "
        szSql &= "             S41.mnf_cnd_tag = 'WAFER CASE NO' "
        szSql &= "             AND  S41.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "      ) UNION_TABLE " 'UPD MIAO 2018/10/31
        szSql &= "      WHERE "
        szSql &= "         UNION_TABLE.rack1 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack2 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack3 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack4 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack5 = '" + txtRackNo.Text + "' "
        szSql &= "    ) B " 'UPD MIAO 2018/10/31
        szSql &= "ON "
        szSql &= "    A.lot_no =  B.lot_no "
        szSql &= "AND "
        szSql &= "    A.opt_time = B.update_time "
        szSql &= "AND "
        szSql &= "    A.type = B.type "
        szSql &= "WHERE "
        szSql &= "    A.koutei_cd in('S311','S31','A31','S41') "
        szSql &= "ORDER BY "
        szSql &= "  A.diff_lot, A.lot_no, A.opt_time "
        szSql &= " ,B.lot_no, B.update_time, B.type " 'ADD MIAO 2018/10/31
        szSql &= "Limit " + serchMaxCount.ToString

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsNothing(dt) Then
            getDataWaferCase = New DataTable
        Else
            getDataWaferCase = dt
        End If
    End Function


    '検索条件にヒットする件数を取得する。(ラック)
    Private Function getDataCountRack() As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT "
        szSql &= "  COUNT(*) COUNT " 'UPD MIAO 2018/10/31
        szSql &= "FROM "
        szSql &= "    MAT.l_sf_work_rslt_head AS A "
        szSql &= "RIGHT JOIN "
        szSql &= "    ( "
        szSql &= "      SELECT * "
        szSql &= "      FROM "
        szSql &= "      ( "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S41.lot_no as lot_no, "
        szSql &= "            S41.type AS type, "
        szSql &= "            MAX(CASE WHEN S41.seq = '1' THEN S41.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '2' THEN S41.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '3' THEN S41.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '4' THEN S41.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '5' THEN S41.actual_model END) AS rack5 , "
        szSql &= "            S41.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S41 AS S41 "
        szSql &= "        WHERE  "
        szSql &= "             S41.mnf_cnd_tag = 'RACK NO' "
        szSql &= "             AND  S41.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A801.lot_no AS lot_no, "
        szSql &= "            A801.type AS type, "
        szSql &= "            MAX(CASE WHEN A801.seq = '1' THEN A801.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A801.seq = '2' THEN A801.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A801.seq = '3' THEN A801.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A801.seq = '4' THEN A801.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A801.seq = '5' THEN A801.actual_model END) AS rack5 , "
        szSql &= "            A801.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A801 AS A801 "
        szSql &= "        WHERE  "
        szSql &= "             A801.mnf_cnd_tag = 'RACK NO' "
        szSql &= "             AND  A801.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S42.lot_no AS lot_no, "
        szSql &= "            S42.type AS type, "
        szSql &= "            MAX(CASE WHEN S42.seq = '1' THEN S42.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S42.seq = '2' THEN S42.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S42.seq = '3' THEN S42.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S42.seq = '4' THEN S42.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S42.seq = '5' THEN S42.actual_model END) AS rack5 , "
        szSql &= "            S42.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S42 AS S42 "
        szSql &= "        WHERE  "
        szSql &= "             S42.mnf_cnd_tag = 'RACK NO' "
        szSql &= "             AND  S42.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S51.lot_no AS lot_no,  "
        szSql &= "            S51.type AS type, "
        szSql &= "            MAX(CASE WHEN S51.seq = '1' THEN S51.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '2' THEN S51.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '3' THEN S51.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '4' THEN S51.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '5' THEN S51.actual_model END) AS rack5 , "
        szSql &= "            S51.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S51 AS S51 "
        szSql &= "        WHERE  "
        szSql &= "             S51.mnf_cnd_tag = 'RACK NO' "
        szSql &= "             AND  S51.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "      ) UNION_TABLE " 'UPD MIAO 2018/10/31
        szSql &= "      WHERE "
        szSql &= "         UNION_TABLE.rack1 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack2 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack3 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack4 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack5 = '" + txtRackNo.Text + "' "
        szSql &= "    ) B " 'UPD MIAO 2018/10/31
        szSql &= "ON "
        szSql &= "    A.lot_no =  B.lot_no "
        szSql &= "AND "
        szSql &= "    A.opt_time = B.update_time "
        szSql &= "AND "
        szSql &= "    A.type = B.type "
        szSql &= "WHERE "
        szSql &= "    A.koutei_cd in ('S41','A801','S42','S51') "
        szSql &= "  ORDER BY B.lot_no, B.update_time, B.type " 'ADD MIAO 2018/10/31

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsNothing(dt) Then
            getDataCountRack = New DataTable
        Else
            getDataCountRack = dt
        End If
    End Function

    '検索条件にヒットするデータを取得する。(ラック)
    Private Function getDataRack() As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT  "
        szSql &= "    A.lot_no, "
        szSql &= "    A.diff_lot AS wafer_lotno, "
        szSql &= "    A.koutei_cd, "
        szSql &= "    CASE WHEN A.type = '1' THEN '" + htMsgMst("MSG10040") + "' "
        szSql &= "         WHEN A.type = '2' THEN '" + htMsgMst("MSG10041") + "' "
        szSql &= "         WHEN A.type = '3' THEN '" + htMsgMst("MSG10042") + "' "
        szSql &= "    END AS status,  "
        szSql &= "    A.opt_time, "
        szSql &= "    B.rack1, "
        szSql &= "    B.rack2, "
        szSql &= "    B.rack3, "
        szSql &= "    B.rack4, "
        szSql &= "    B.rack5 "
        szSql &= "FROM "
        szSql &= "    MAT.l_sf_work_rslt_head AS A "
        szSql &= "RIGHT JOIN "
        szSql &= "    ( "
        szSql &= "      SELECT * "
        szSql &= "      FROM "
        szSql &= "      ( "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S41.lot_no as lot_no, "
        szSql &= "            S41.type AS type, "
        szSql &= "            MAX(CASE WHEN S41.seq = '1' THEN S41.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '2' THEN S41.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '3' THEN S41.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '4' THEN S41.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S41.seq = '5' THEN S41.actual_model END) AS rack5 , "
        szSql &= "            S41.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S41 AS S41 "
        szSql &= "        WHERE  "
        szSql &= "             S41.mnf_cnd_tag = 'RACK NO' "
        szSql &= "             AND  S41.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A801.lot_no AS lot_no, "
        szSql &= "            A801.type AS type, "
        szSql &= "            MAX(CASE WHEN A801.seq = '1' THEN A801.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A801.seq = '2' THEN A801.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A801.seq = '3' THEN A801.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A801.seq = '4' THEN A801.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A801.seq = '5' THEN A801.actual_model END) AS rack5 , "
        szSql &= "            A801.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A801 AS A801 "
        szSql &= "        WHERE  "
        szSql &= "             A801.mnf_cnd_tag = 'RACK NO' "
        szSql &= "             AND  A801.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S42.lot_no AS lot_no, "
        szSql &= "            S42.type AS type, "
        szSql &= "            MAX(CASE WHEN S42.seq = '1' THEN S42.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S42.seq = '2' THEN S42.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S42.seq = '3' THEN S42.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S42.seq = '4' THEN S42.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S42.seq = '5' THEN S42.actual_model END) AS rack5 , "
        szSql &= "            S42.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S42 AS S42 "
        szSql &= "        WHERE  "
        szSql &= "             S42.mnf_cnd_tag = 'RACK NO' "
        szSql &= "             AND  S42.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S51.lot_no AS lot_no,  "
        szSql &= "            S51.type AS type, "
        szSql &= "            MAX(CASE WHEN S51.seq = '1' THEN S51.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '2' THEN S51.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '3' THEN S51.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '4' THEN S51.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '5' THEN S51.actual_model END) AS rack5 , "
        szSql &= "            S51.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S51 AS S51 "
        szSql &= "        WHERE  "
        szSql &= "             S51.mnf_cnd_tag = 'RACK NO' "
        szSql &= "             AND  S51.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "      ) UNION_TABLE " 'UPD MIAO 2018/10/31
        szSql &= "      WHERE "
        szSql &= "         UNION_TABLE.rack1 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack2 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack3 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack4 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack5 = '" + txtRackNo.Text + "' "
        szSql &= "    ) B " 'UPD MIAO 2018/10/31
        szSql &= "ON "
        szSql &= "    A.lot_no =  B.lot_no "
        szSql &= "AND "
        szSql &= "    A.opt_time = B.update_time "
        szSql &= "AND "
        szSql &= "    A.type = B.type "
        szSql &= "WHERE "
        szSql &= "    A.koutei_cd in ('S41','A801','S42','S51') "
        szSql &= "ORDER BY A.diff_lot, A.lot_no, A.opt_time "
        szSql &= " ,B.lot_no, B.update_time,B.type " 'ADD MIAO 2018/10/31

        szSql &= "Limit " + serchMaxCount.ToString

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsNothing(dt) Then
            getDataRack = New DataTable
        Else
            getDataRack = dt
        End If
    End Function


    '検索条件にヒットする件数を取得する。(MSラック)
    Private Function getDataCountMsRack() As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT "
        szSql &= "  COUNT(*) COUNT " 'UPD MIAO 2018/10/31
        szSql &= "FROM "
        szSql &= "    MAT.l_sf_work_rslt_head AS A "
        szSql &= "RIGHT JOIN "
        szSql &= "    ( "
        szSql &= "      SELECT * "
        szSql &= "      FROM "
        szSql &= "      ( "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S51.lot_no as lot_no, "
        szSql &= "            S51.type AS type, "
        szSql &= "            MAX(CASE WHEN S51.seq = '1' THEN S51.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '2' THEN S51.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '3' THEN S51.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '4' THEN S51.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '5' THEN S51.actual_model END) AS rack5 , "
        szSql &= "            S51.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S51 AS S51 "
        szSql &= "        WHERE  "
        szSql &= "             S51.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  S51.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A10.lot_no AS lot_no, "
        szSql &= "            A10.type AS type, "
        szSql &= "            MAX(CASE WHEN A10.seq = '1' THEN A10.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A10.seq = '2' THEN A10.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A10.seq = '3' THEN A10.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A10.seq = '4' THEN A10.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A10.seq = '5' THEN A10.actual_model END) AS rack5 , "
        szSql &= "            A10.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A10 AS A10 "
        szSql &= "        WHERE  "
        szSql &= "             A10.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  A10.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A54.lot_no AS lot_no, "
        szSql &= "            A54.type AS type, "
        szSql &= "            MAX(CASE WHEN A54.seq = '1' THEN A54.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A54.seq = '2' THEN A54.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A54.seq = '3' THEN A54.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A54.seq = '4' THEN A54.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A54.seq = '5' THEN A54.actual_model END) AS rack5 , "
        szSql &= "            A54.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A54 AS A54 "
        szSql &= "        WHERE  "
        szSql &= "             A54.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  A54.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S121.lot_no AS lot_no,  "
        szSql &= "            S121.type AS type, "
        szSql &= "            MAX(CASE WHEN S121.seq = '1' THEN S121.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S121.seq = '2' THEN S121.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S121.seq = '3' THEN S121.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S121.seq = '4' THEN S121.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S121.seq = '5' THEN S121.actual_model END) AS rack5 , "
        szSql &= "            S121.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S121 AS S121 "
        szSql &= "        WHERE  "
        szSql &= "             S121.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  S121.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S122.lot_no AS lot_no,  "
        szSql &= "            S122.type AS type, "
        szSql &= "            MAX(CASE WHEN S122.seq = '1' THEN S122.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S122.seq = '2' THEN S122.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S122.seq = '3' THEN S122.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S122.seq = '4' THEN S122.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S122.seq = '5' THEN S122.actual_model END) AS rack5 , "
        szSql &= "            S122.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S122 AS S122 "
        szSql &= "        WHERE  "
        szSql &= "             S122.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  S122.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        UNION ALL "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A121.lot_no AS lot_no,  "
        szSql &= "            A121.type AS type, "
        szSql &= "            MAX(CASE WHEN A121.seq = '1' THEN A121.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A121.seq = '2' THEN A121.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A121.seq = '3' THEN A121.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A121.seq = '4' THEN A121.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A121.seq = '5' THEN A121.actual_model END) AS rack5 , "
        szSql &= "            A121.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A121 AS A121 "
        szSql &= "        WHERE  "
        szSql &= "             A121.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  A121.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A122.lot_no AS lot_no,  "
        szSql &= "            A122.type AS type, "
        szSql &= "            MAX(CASE WHEN A122.seq = '1' THEN A122.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A122.seq = '2' THEN A122.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A122.seq = '3' THEN A122.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A122.seq = '4' THEN A122.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A122.seq = '5' THEN A122.actual_model END) AS rack5 , "
        szSql &= "            A122.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A122 AS A122 "
        szSql &= "        WHERE  "
        szSql &= "             A122.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  A122.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A12J.lot_no AS lot_no,  "
        szSql &= "            A12J.type AS type, "
        szSql &= "            MAX(CASE WHEN A12J.seq = '1' THEN A12J.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A12J.seq = '2' THEN A12J.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A12J.seq = '3' THEN A12J.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A12J.seq = '4' THEN A12J.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A12J.seq = '5' THEN A12J.actual_model END) AS rack5 , "
        szSql &= "            A12J.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A12J AS A12J "
        szSql &= "        WHERE  "
        szSql &= "             A12J.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  A12J.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A53.lot_no AS lot_no,  "
        szSql &= "            A53.type AS type, "
        szSql &= "            MAX(CASE WHEN A53.seq = '1' THEN A53.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A53.seq = '2' THEN A53.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A53.seq = '3' THEN A53.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A53.seq = '4' THEN A53.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A53.seq = '5' THEN A53.actual_model END) AS rack5 , "
        szSql &= "            A53.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A53 AS A53 "
        szSql &= "        WHERE  "
        szSql &= "             A53.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  A53.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        union all "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S313.lot_no AS lot_no,  "
        szSql &= "            S313.type AS type, "
        szSql &= "            MAX(CASE WHEN S313.seq = '1' THEN S313.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S313.seq = '2' THEN S313.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S313.seq = '3' THEN S313.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S313.seq = '4' THEN S313.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S313.seq = '5' THEN S313.actual_model END) AS rack5 , "
        szSql &= "            S313.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S313 AS S313 "
        szSql &= "        WHERE  "
        szSql &= "             S313.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  S313.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "      ) UNION_TABLE " 'UPD MIAO 2018/10/31
        szSql &= "      WHERE "
        szSql &= "         UNION_TABLE.rack1 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack2 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack3 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack4 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack5 = '" + txtRackNo.Text + "' "
        szSql &= "    ) B " 'UPD MIAO 2018/10/31
        szSql &= "ON "
        szSql &= "    A.lot_no =  B.lot_no "
        szSql &= "AND "
        szSql &= "    A.opt_time = B.update_time "
        szSql &= "AND "
        szSql &= "    A.type = B.type "
        szSql &= "WHERE "
        szSql &= "    A.koutei_cd in ('S51', 'A10', 'A54', 'S121', 'S122', 'A121', 'A122', 'A12J', 'A53', 'S313') "
        szSql &= " ORDER BY B.lot_no, B.update_time,B.type " 'ADD MIAO 2018/10/31

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsNothing(dt) Then
            getDataCountMsRack = New DataTable
        Else
            getDataCountMsRack = dt
        End If
    End Function

    '検索条件にヒットするデータを取得する。(MSラック)
    Private Function getDataMsRack() As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT  "
        szSql &= "    A.lot_no, "
        szSql &= "    A.diff_lot AS wafer_lotno, "
        szSql &= "    A.koutei_cd, "
        szSql &= "    CASE WHEN A.type = '1' THEN '" + htMsgMst("MSG10040") + "' "
        szSql &= "         WHEN A.type = '2' THEN '" + htMsgMst("MSG10041") + "' "
        szSql &= "         WHEN A.type = '3' THEN '" + htMsgMst("MSG10042") + "' "
        szSql &= "    END AS status,  "
        szSql &= "    A.opt_time, "
        szSql &= "    B.rack1, "
        szSql &= "    B.rack2, "
        szSql &= "    B.rack3, "
        szSql &= "    B.rack4, "
        szSql &= "    B.rack5 "
        szSql &= "FROM "
        szSql &= "    MAT.l_sf_work_rslt_head AS A "
        szSql &= "RIGHT JOIN "
        szSql &= "    ( "
        szSql &= "      SELECT * "
        szSql &= "      FROM "
        szSql &= "      ( "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S51.lot_no as lot_no, "
        szSql &= "            S51.type AS type, "
        szSql &= "            MAX(CASE WHEN S51.seq = '1' THEN S51.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '2' THEN S51.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '3' THEN S51.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '4' THEN S51.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S51.seq = '5' THEN S51.actual_model END) AS rack5 , "
        szSql &= "            S51.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S51 AS S51 "
        szSql &= "        WHERE  "
        szSql &= "             S51.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  S51.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        UNION ALL "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A10.lot_no AS lot_no, "
        szSql &= "            A10.type AS type, "
        szSql &= "            MAX(CASE WHEN A10.seq = '1' THEN A10.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A10.seq = '2' THEN A10.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A10.seq = '3' THEN A10.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A10.seq = '4' THEN A10.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A10.seq = '5' THEN A10.actual_model END) AS rack5 , "
        szSql &= "            A10.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A10 AS A10 "
        szSql &= "        WHERE  "
        szSql &= "             A10.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  A10.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        UNION ALL "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A54.lot_no AS lot_no, "
        szSql &= "            A54.type AS type, "
        szSql &= "            MAX(CASE WHEN A54.seq = '1' THEN A54.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A54.seq = '2' THEN A54.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A54.seq = '3' THEN A54.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A54.seq = '4' THEN A54.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A54.seq = '5' THEN A54.actual_model END) AS rack5 , "
        szSql &= "            A54.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A54 AS A54 "
        szSql &= "        WHERE  "
        szSql &= "             A54.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  A54.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        UNION ALL "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S121.lot_no AS lot_no,  "
        szSql &= "            S121.type AS type, "
        szSql &= "            MAX(CASE WHEN S121.seq = '1' THEN S121.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S121.seq = '2' THEN S121.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S121.seq = '3' THEN S121.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S121.seq = '4' THEN S121.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S121.seq = '5' THEN S121.actual_model END) AS rack5 , "
        szSql &= "            S121.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S121 AS S121 "
        szSql &= "        WHERE  "
        szSql &= "             S121.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  S121.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        UNION ALL "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S122.lot_no AS lot_no,  "
        szSql &= "            S122.type AS type, "
        szSql &= "            MAX(CASE WHEN S122.seq = '1' THEN S122.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S122.seq = '2' THEN S122.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S122.seq = '3' THEN S122.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S122.seq = '4' THEN S122.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S122.seq = '5' THEN S122.actual_model END) AS rack5 , "
        szSql &= "            S122.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S122 AS S122 "
        szSql &= "        WHERE  "
        szSql &= "             S122.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  S122.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        UNION ALL "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A121.lot_no AS lot_no,  "
        szSql &= "            A121.type AS type, "
        szSql &= "            MAX(CASE WHEN A121.seq = '1' THEN A121.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A121.seq = '2' THEN A121.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A121.seq = '3' THEN A121.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A121.seq = '4' THEN A121.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A121.seq = '5' THEN A121.actual_model END) AS rack5 , "
        szSql &= "            A121.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A121 AS A121 "
        szSql &= "        WHERE  "
        szSql &= "             A121.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  A121.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        UNION ALL "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A122.lot_no AS lot_no,  "
        szSql &= "            A122.type AS type, "
        szSql &= "            MAX(CASE WHEN A122.seq = '1' THEN A122.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A122.seq = '2' THEN A122.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A122.seq = '3' THEN A122.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A122.seq = '4' THEN A122.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A122.seq = '5' THEN A122.actual_model END) AS rack5 , "
        szSql &= "            A122.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A122 AS A122 "
        szSql &= "        WHERE  "
        szSql &= "             A122.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  A122.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        UNION ALL "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A12J.lot_no AS lot_no,  "
        szSql &= "            A12J.type AS type, "
        szSql &= "            MAX(CASE WHEN A12J.seq = '1' THEN A12J.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A12J.seq = '2' THEN A12J.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A12J.seq = '3' THEN A12J.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A12J.seq = '4' THEN A12J.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A12J.seq = '5' THEN A12J.actual_model END) AS rack5 , "
        szSql &= "            A12J.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A12J AS A12J "
        szSql &= "        WHERE  "
        szSql &= "             A12J.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  A12J.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        UNION ALL "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            A53.lot_no AS lot_no,  "
        szSql &= "            A53.type AS type, "
        szSql &= "            MAX(CASE WHEN A53.seq = '1' THEN A53.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN A53.seq = '2' THEN A53.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN A53.seq = '3' THEN A53.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN A53.seq = '4' THEN A53.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN A53.seq = '5' THEN A53.actual_model END) AS rack5 , "
        szSql &= "            A53.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_A53 AS A53 "
        szSql &= "        WHERE  "
        szSql &= "             A53.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  A53.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "        UNION ALL "
        szSql &= "        ( "
        szSql &= "        SELECT  "
        szSql &= "            S313.lot_no AS lot_no,  "
        szSql &= "            S313.type AS type, "
        szSql &= "            MAX(CASE WHEN S313.seq = '1' THEN S313.actual_model END) AS rack1 , "
        szSql &= "            MAX(CASE WHEN S313.seq = '2' THEN S313.actual_model END) AS rack2 , "
        szSql &= "            MAX(CASE WHEN S313.seq = '3' THEN S313.actual_model END) AS rack3 , "
        szSql &= "            MAX(CASE WHEN S313.seq = '4' THEN S313.actual_model END) AS rack4 , "
        szSql &= "            MAX(CASE WHEN S313.seq = '5' THEN S313.actual_model END) AS rack5 , "
        szSql &= "            S313.update_time AS update_time "
        szSql &= "        FROM  "
        szSql &= "            mat.l_sf_work_rslt_S313 AS S313 "
        szSql &= "        WHERE  "
        szSql &= "             S313.mnf_cnd_tag in ('COMP MS RACK NO', 'ACCEPTED RACK NO' ) "
        szSql &= "             AND  S313.update_time between timestamp '" + FromDate + "' and timestamp '" + ToDate + "' "
        szSql &= "        GROUP BY lot_no, update_time, type "
        'szSql &= "        ORDER BY lot_no, update_time, type "
        szSql &= "        ) "
        szSql &= "      ) UNION_TABLE " 'UPD MIAO 2018/10/31
        szSql &= "      WHERE "
        szSql &= "         UNION_TABLE.rack1 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack2 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack3 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack4 = '" + txtRackNo.Text + "' "
        szSql &= "      OR UNION_TABLE.rack5 = '" + txtRackNo.Text + "' "
        szSql &= "    ) B " 'UPD MIAO 2018/10/31
        szSql &= "ON "
        szSql &= "    A.lot_no =  B.lot_no "
        szSql &= "AND "
        szSql &= "    A.opt_time = B.update_time "
        szSql &= "AND "
        szSql &= "    A.type = B.type "
        szSql &= "WHERE "
        szSql &= "    A.koutei_cd in ('S51', 'A10', 'A54', 'S121', 'S122', 'A121', 'A122', 'A12J', 'A53', 'S313') "
        szSql &= "ORDER BY A.diff_lot, A.lot_no, A.opt_time "
        szSql &= ",B.lot_no, B.update_time, B.type " 'ADD MIAO 2018/10/31
        szSql &= "Limit " + serchMaxCount.ToString

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsNothing(dt) Then
            getDataMsRack = New DataTable
        Else
            getDataMsRack = dt
        End If
    End Function

    'DBから最大検索数を取得する。
    Private Sub getSerchMaxCount()
        Dim szSql As String = ""
        szSql &= " SELECT "
        szSql &= "     num_param2 "
        szSql &= " FROM "
        szSql &= "     KAD.t_factory_info "
        szSql &= " WHERE "
        szSql &= "     param_id = '9998' "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        'DBに最大取得件数が設定されている場合は、取得件数を更新する。
        If Not IsNothing(dt) Then
            Try
                Dim intCount As Integer = CInt(dt.Rows(0)("num_param1"))
                'DB登録値が1以上の場合は検索上限値に設定する。
                If intCount > 1 Then
                    serchMaxCount = CInt(dt.Rows(0)("num_param1"))
                End If
            Catch ex As Exception
                '数値変換できない場合はデフォルト値を使用する。
            End Try
        End If

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnCsvOutput.Click
        'SaveFileDialogクラスのインスタンスを作成
        Dim sfd As New SaveFileDialog()

        sfd.FileName = fileName
        'はじめに表示されるフォルダを指定する
        '指定しない（空の文字列）の時は、現在のディレクトリが表示される
        sfd.InitialDirectory = "C:\"
        '[ファイルの種類]に表示される選択肢を指定する
        sfd.Filter = "すべてのファイル(*.*)|*.*"
        '[ファイルの種類]ではじめに選択されるものを指定する
        '2番目の「すべてのファイル」が選択されているようにする
        sfd.FilterIndex = 1
        'タイトルを設定する
        sfd.Title = fileSaveTitle
        'ダイアログボックスを閉じる前に現在のディレクトリを復元するようにする
        sfd.RestoreDirectory = True
        '既に存在するファイル名を指定したとき警告する
        'デフォルトでTrueなので指定する必要はない
        sfd.OverwritePrompt = True
        '存在しないパスが指定されたとき警告を表示する
        'デフォルトでTrueなので指定する必要はない
        sfd.CheckPathExists = True

        'ダイアログを表示する
        If sfd.ShowDialog() = DialogResult.OK Then
            'OKボタンがクリックされたとき、CSVファイル作成を行う。
            createCSV(sfd.FileName)
        End If
    End Sub

    Private Sub createCSV(ByVal filePath As String)

    End Sub
    'ADD MIAO 2018/10/17 Begin
    Public Function DBNullTOblank(obj As Object) As String
        DBNullTOblank = IIf(IsDBNull(obj), "", obj)
    End Function
    'ADD MIAO 2018/10/17 END
End Class